<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery.min.js"></script>
</head>

<body>
    <div index="1" data-index="2">div</div>
    <span>12345</span>
    <script>
        $("span").data("name", "xy");
        console.log($("span").data("name"));
        console.log($("div").data("index"));
    </script>
</body>

</html>